<?php

namespace App\Models;

use Eloquent as Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * Class Order
 * @package App\Models
 * @version February 22, 2018, 3:24 am UTC
 *
 * @property integer user_id
 * @property integer customer_id
 * @property decimal price
 * @property integer number
 * @property integer type
 * @property integer status
 * @property string remark
 * @property string sn
 * @property string province
 * @property string created_date
 */
class Order extends Model
{
    use SoftDeletes;

    public $table = 'orders';
    

    protected $dates = ['deleted_at'];


    public $fillable = [
        'user_id',
        'customer_id',
        'price',
        'number',
        'type',
        'status',
        'remark',
        'sn',
        'province',
        'created_date'
    ];

    /**
     * The attributes that should be casted to native types.
     *
     * @var array
     */
    protected $casts = [
        'user_id' => 'integer',
        'customer_id' => 'integer',
        'number' => 'integer',
        'type' => 'integer',
        'status' => 'integer',
        'remark' => 'string',
        'sn' => 'string',
        'province' => 'string',
        'created_date' => 'string'
    ];

    /**
     * Validation rules
     *
     * @var array
     */
    public static $rules = [
        
    ];

    public function goods()
    {
        return $this->belongsToMany('App\Models\Goods','order_goods')->withPivot('color_id','number','price');
    }

    public function user()
    {
        return $this->belongsTo('App\User');
    }

    public function customer()
    {
        return $this->belongsTo('App\User','customer_id');
    }
}
